var i_im_allow_file_type = ['jpg','gif', 'png', 'zip','rar'];
var i_im_max_file_size = '2048';
var i_im_baseUrl = "http://livingim.com/";
var i_im_rometor = 0;
/**
*	文件上传
*/
function submitform(){
	var id = arguments[0]?arguments[0]:'';//如有传值则为后台
	if(!i_im_checkFileType("impostfile")){
		alert("不是许可的文件");
		return false;
	}
	if(!i_im_checkFileSize("impostfile")){
		alert("文件超出最大限制");
		return false;
	}
/*	var msg_transferfile = document.createElement("div");
	msg_transferfile.className = "msgSys";
	var msg = "正在传送文件:" + i_im_$("impostfile").value;
//	msg_transferfile.innerHTML = msg;
	
	i_im_$("history").appendChild(msg_transferfile);*/
	i_im_$("pbform").submit();
	var msg = "正在传送文件:" + i_im_$("impostfile").value;
	i_im_$("impostfile").value = "";
	if(id>0)
		i_im_rometor = id;
	sending(id,msg);
}

//客户端判断文件类型
function i_im_checkFileType(file) {
	var fileName = document.getElementById(file).value.toLowerCase();
	var pos = fileName.lastIndexOf(".");
	var ext = fileName.substring(pos+1,fileName.length);
	i_im_allow_file_type = i_im_allow_file_type.toString();
	var i_im_allow_file_type_array = i_im_allow_file_type.split(",");
	for(var i=0;i<i_im_allow_file_type_array.length;i++){
		if(ext==i_im_allow_file_type_array[i]){
			return true;
		}
	}
	return false;
}

//客户端判断文件大小
function i_im_checkFileSize(file) {
	var fileIsSize;
	var dFile = document.getElementById(file);

	var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
    (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
    (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
    (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

    if (Sys.ie=='6.0'){
    	file = dFile.value;
		var image = new Image();
		image.dynsrc = file;
		fileIsSize = image.fileSize;
		if(fileIsSize<0){
			return true;
		}
    }else if(Sys.ie=='7.0' || Sys.ie=='8.0'){
        return true;
	}else if(Sys.firefox || Sys.chrome || Sys.safari){
		fileIsSize = dFile.files[0].fileSize;
	}else if(Sys.opera){
		return true;
	}else{
		return true;
	}
    if(fileIsSize>i_im_max_file_size){
    	return false;
    }else{
    	return true;
    }
}

var i_im_$ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

var i_im_Class = {
	create: function() {
		return function() { this.initialize.apply(this, arguments); }
	}
}

var i_im_Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
}

	//文件失败后回调函数
backTransferFileError = function(msg){
	alert(msg);
	var msg_transferfile = document.createElement("div");
	msg_transferfile.className = "msgSys";
	var msg = i_im_lang_file.TransferFailed;
	msg_transferfile.innerHTML = msg;
	i_im_$("history").appendChild(msg_transferfile);
}


	//文件传输后回调函数
function backAutoSendMsg(msg) {
	var v = msg;

	if(v) {
		// 获取好友的详情
/*		if(frendlistarrayobj[id]) {
			var pals_obj = frendlistarrayobj[id];
		} else {
			i_im_getFriendInfo(id);
			if(getFriendInfo_id!=id) {
				setTimeout("i_im_talkWin('"+id+"','"+name+"')",1000);
				getFriendInfo_id = id;
			}
			return false;
		}
*/		
	if(i_im_rometor>0)
		sending(i_im_rometor,v);
	else
		sending(v);
	/*	i_im_ajax(i_im_baseUrl+"waiting.php","POST","pals="+pals_obj.pals_id+"&v="+v+"&vc="+verify_code,function(data){
			if(data==1) {
				i_im_getMessage();
			} else {
				alert(i_im_lang_talkwin.NowTransferFile);
			}
		});
	*/
	}
}